package com.ben.chatroom.common.entity;

import lombok.Data;

/**
 * @author huangyijun
 */
@Data
public class ImUser {

  String userId;
  String userName;
  String devId;
  String token;
  String nickName = "nickName";
  PLATTYPE platform = PLATTYPE.WINDOWS;


  public enum PLATTYPE {
    WINDOWS, MAC, ANDROID, IOS, WEB, OTHER;
  }

  private String sessionId;


  public void setPlatform(int platform) {
    PLATTYPE[] values = PLATTYPE.values();
    for(PLATTYPE value : values) {
      if(value.ordinal() == platform) {
        this.platform = value;
      }
    }

  }


  @Override
  public String toString() {
    return "User{" +
      "uid='" + userId + '\'' +
      ", devId='" + devId + '\'' +
      ", token='" + token + '\'' +
      ", nickName='" + nickName + '\'' +
      ", platform=" + platform +
      '}';
  }

  public static ImUser fromMsg(ProtoMsg.LoginRequest info) {
    ImUser user = new ImUser();
    user.userId = info.getUid();
    user.devId = info.getDeviceId();
    user.token = info.getToken();
    user.setPlatform(info.getPlatform());
    return user;
  }

}
